import { MenuItemDefinition } from '@amcax/base';
import { ctx2 } from '@app-cad/module';
import { HookAPI } from 'antd/es/modal/useModal';
import { ProductTreeNode } from '../../types';

export const removeMeasurement: MenuItemDefinition<ProductTreeNode> = {
  id: 'remove-assembly-child',
  children: '移除',
  hidden: ({ props: { type } }) => type !== 'measurement',
  onClick: async ({ data, props: doc }) => {
    const { title, key } = doc;

    const confirmed = await (data.modal as HookAPI).confirm({
      closable: true,
      title: '移除测量',
      content: `确认移除 ${title} 吗？`,
      okText: '移除',
      okType: 'danger',
      cancelText: '取消',
    });

    if (confirmed) {
      await ctx2.commandCenters.basicCommands.deleteObjects([key]);
    }
  },
};
